Page({
  data: {

		isFirstTop:false,
		isShowRules:false,
		rangMore:{},

		mineRang:{},

	},

	startGame(){

		my.showLoading();

		getApp().cloud.function.invoke('client',{},"getCurrentUserInfo").then(res => {
			console.log('获取剩余游戏次数=====>',res);
			
			my.hideLoading();

			if(res.data.game_left_num <= 0){
				my.navigateTo({
					url: '../drawResult/drawResult?end=gameNo'
				});
			}else{
				my.navigateTo({
					url: '../game/game'
				});
			}
		})
		
		
	},

	//跳转页面
	goPage(e){
		my.navigateTo({
			url: e.target.dataset.url
		});
	},

	showRules(){
		this.setData({
			isShowRules:true
		})
	},

	obtainTop(){
		my.showLoading();
		getApp().cloud.function.invoke('game',{limit:10},"rankingList").then(res => {
			console.log('获取排行榜信息==>',res); 
			
			const that = this;
			
      my.hideLoading({
        page: that,  // 防止执行时已经切换到其它页面，page指向不准确
			});
			
			
			if(res.code != 0){
				my.showToast({content:res.msg});
				return
			}
			
			this.setData({
				rangMore:res.data
			})


		}) 
	},

	mineTop(){
		getApp().cloud.function.invoke('game',{},"myRanking").then(res => {
			console.log('获取我的排名信息==>',res); 

			if(res.code != 0){
				my.showToast({content:res.msg});
				return
			}

			if(res.data.ranking <= 3){
				this.setData({
					isFirstTop:true,
					mineRang:res.data
				})
			}else{
				my.authorize({
					scopes: 'scope.userInfo',
					success: () => {
						my.getAuthUserInfo({
							success: (userInfo) => {
								
								res.data.avatar = userInfo.avatar

								this.setData({
									isFirstTop:false,
									mineRang:res.data
								})
							}
						});
					},
				});
			}

		}) 
	},
	
	onShow(){
		this.obtainTop();
		this.mineTop()
	},

  onLoad() {},
});
